#include<bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;
const int N=5e5+5;
int n,c;
int b[N];
vector<int>a[N];
vector<pair<int,int>>p;
map<int,int>g;
signed main(){
	freopen("list.in","r",stdin);
	freopen("list.out","w",stdout);
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>n;int sum=0;
	for(int i=1;i<=n;i++){
		int k;cin>>k,a[i].resize(k);
		for(int &x:a[i])cin>>x;
	}
	cin>>c;
	for(int i=1;i<=n;i++)cin>>b[i],b[i]*=i;
	for(int i=n;i>=1;i--)b[i]-=b[i-1];
	vector<int>q={1};
	for(int i=1;i<=n;i++){
		if(a[i].empty())continue;
		g[a[i].front()]++,sum+=b[g[a[i].front()]];
		for(int j=0;j+1<a[i].size();j++){
			p.push_back({a[i][j+1]-a[i][j]+1,a[i][j+1]});
			q.push_back(a[i][j+1]-a[i][j]+1),sum+=(a[i][j+1]-a[i][j])*c;
		}
	}
	sort(p.begin(),p.end(),greater<>()),sort(q.begin(),q.end(),greater<>());
	q.erase(unique(q.begin(),q.end()),q.end());
	int k=0,ans=1e18,cnt=n;vector<int>A;
	for(int x:q){
		while(k<p.size()&&p[k].first>x){
			sum-=(p[k].first-1)*c;
			g[p[k].second]++,sum+=b[g[p[k].second]],cnt++,k++;
		}
		if(sum+cnt*x*c<ans){
			ans=sum+cnt*x*c,A={x};
		}else if(sum+cnt*x*c==ans)A.push_back(x);
	}sort(A.begin(),A.end());
	cout<<ans<<' '<<A.size()<<endl;
	for(int x:A)cout<<x<<' ';cout<<endl;
	return 0;
}